<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="11" :md="12" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.itemName"></a-input>
              <!-- <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.authorizationDeadline_begin"></j-date> -->
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('软件运维计划表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
            selectedRowKeys.length
        }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap" :scroll="{ x: true }"
        :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading" :customRow="customRow"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <!-- 项目类型插槽 -->
        <template slot="itemType" slot-scope="text">
          <a-tag v-if="text == '1'" color="blue">软件项目</a-tag>
          <a-tag v-if="text == '2'" color="purple">硬件项目</a-tag>
          <a-tag v-if="text == '3'">混合项目</a-tag>
          <!-- <span v-if="text == '1'">新增</span>
          <span v-if="text == '2'">变更</span>
          <span v-if="text == '3'">取消</span> -->
        </template>

        <!-- 软件授权类型插槽 -->
        <template slot="softwareLicenseType" slot-scope="text">
          <a-tag v-if="text == '1'" color="blue">年付费</a-tag>
          <a-tag v-if="text == '2'" color="purple">永久产权</a-tag>
          <a-tag v-if="text == '3'">有截止日</a-tag>
          <!-- <span v-if="text == '1'">新增</span>
          <span v-if="text == '2'">变更</span>
          <span v-if="text == '3'">取消</span> -->
        </template>

        <!-- 是否放弃维保插槽 -->
        <template slot="isAbandonMaintenance" slot-scope="text">
          <a-tag v-if="text == '1'" color="blue">否</a-tag>
          <a-tag v-if="text == '2'" color="purple">是</a-tag>
          <!-- <a-tag v-if="text == '3'" >有截止日</a-tag> -->
          <!-- <span v-if="text == '1'">新增</span>
          <span v-if="text == '2'">变更</span>
          <span v-if="text == '3'">取消</span> -->
        </template>


        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ch-software-operation-plan-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import ChSoftwareOperationPlanModal from './modules/ChSoftwareOperationPlanModal'
import '@/assets/less/TableExpand.less'

export default {
  name: "ChSoftwareOperationPlanList",
  mixins: [JeecgListMixin],
  components: {
    ChSoftwareOperationPlanModal
  },
  data() {
    return {
      queryParam: {
        itemName: ''
      },
      description: '软件运维计划表管理页面',
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        {
          title: '主项目编号',
          align: "center",
          dataIndex: 'itemNo'
        },
        {
          title: '项目名称',
          align: "center",
          dataIndex: 'itemName'
        },
        {
          title: '项目类型',
          align: "center",
          dataIndex: 'itemType',
          scopedSlots: { customRender: 'itemType' }
        },
        {
          title: '合同总价',
          align: "center",
          dataIndex: 'totalContractPrice'
        },
        {
          title: '运维比例',
          align: "center",
          dataIndex: 'proportion'
        },
        {
          title: '软件套数',
          align: "center",
          dataIndex: 'softwareSetsNum'
        },
        {
          title: '硬件到期时间',
          align: "center",
          dataIndex: 'hardwareExpirTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '软件到期时间',
          align: "center",
          dataIndex: 'softwareExpirTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '软件授权类型',
          align: "center",
          dataIndex: 'softwareLicenseType',
          scopedSlots: { customRender: 'softwareLicenseType' }
        },
        {
          title: '是否放弃维保',
          align: "center",
          dataIndex: 'isAbandonMaintenance',
          scopedSlots: { customRender: 'isAbandonMaintenance' }
        },
        {
          title: '项目责任人',
          align: "center",
          dataIndex: 'projectProjectPeoper',
          // scopedSlots: { customRender: 'projectProjectPeoper' }
        },
        {
          title: '供应商/客户联系人',
          align: "center",
          dataIndex: 'contacts',
          // scopedSlots: { customRender: 'contacts' }
        },
        {
          title: '附件',
          align: "center",
          dataIndex: 'enclosure',
          scopedSlots: { customRender: 'fileSlot' }
        },
        {
          title: '备注',
          align: "center",
          dataIndex: 'remark'
        },
        // {
        //   title:'是否删除（0正常1.删除）',
        //   align:"center",
        //   dataIndex: 'deleted',
        //   scopedSlots: { customRender: 'deleted' }
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: "/ch/chSoftwareOperationPlan/list",
        delete: "/ch/chSoftwareOperationPlan/delete",
        deleteBatch: "/ch/chSoftwareOperationPlan/deleteBatch",
        exportXlsUrl: "/ch/chSoftwareOperationPlan/exportXls",
        importExcelUrl: "ch/chSoftwareOperationPlan/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    console.log("组件created--------");
    this.getSuperFieldList();
  },
  mounted() {
    console.log("组件mounted---");
    this.dataReception()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    dataReception() {
      this.$bus.$on('record', (record) => {
        this.queryParam.id = record.id
        // localStorage.setItem('data', (record.itemName))
        console.log('组件--this.queryParam.id', this.queryParam.id);
      })
    },
    //鼠标双击事件
    customRow(record, index) {
      return {
        on: {
          // 双击
          dblclick: (event) => {
            console.log("record", record);
            console.log("index", index);
            console.log("event", event);
            // 编辑表单
            console.log('编辑表单');
            this.handleEdit(record)
          },
        },
        // on: {
        //   // 单击
        //   click: (event) => {
        //     // 详情表单
        //     console.log('详情表单');
        //     this.handleDetail(record)
        //   },
        // }
      }
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'itemNo', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'itemName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'itemType', text: '项目类型（1.软件项目2.硬件项目3.混合项目）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'totalContractPrice', text: '合同总价', dictCode: '' })
      fieldList.push({ type: 'string', value: 'proportion', text: '运维比例', dictCode: '' })
      fieldList.push({ type: 'int', value: 'softwareSetsNum', text: '软件套数', dictCode: '' })
      fieldList.push({ type: 'date', value: 'hardwareExpirTime', text: '硬件到期时间' })
      fieldList.push({ type: 'date', value: 'softwareExpirTime', text: '软件到期时间' })
      fieldList.push({ type: 'int', value: 'softwareLicenseType', text: '软件授权类型（1.年付费2.永久产权3.有截止日）', dictCode: '' })
      fieldList.push({ type: 'int', value: 'isAbandonMaintenance', text: '是否放弃维保（1.否2.是）', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'enclosure', text: '附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'deleted', text: '是否删除（0正常1.删除）', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>